﻿using System;
using System.Collections.Generic;

namespace SolidQBCPLibrary
{
    public class BCPCredentials
    {

        private string _instanceName;
        private string _databaseName;
        private string _userName;
        private string _password;

        public bool UseIntegratedSecurity;


        public string InstanceName
        {
            get { return (_instanceName); }
            set
            {
                if (String.IsNullOrEmpty(value))
                    throw new ArgumentException("InstanceName", "Not declared a valid InstanceName");

                _instanceName = value;
            }
        }
        public string DatabaseName
        {
            get { return (_databaseName); }
            set
            {
                if (String.IsNullOrEmpty(value))
                    throw new ArgumentException("DatabaseName", "Not declared a valid DatabaseName");

                _databaseName = value;
            }
        }
        public string UserName
        {
            get { return (_userName); }
            set
            {
                if (String.IsNullOrEmpty(value))
                    throw new ArgumentException("User", "User cannot be empty");

                _userName = value;
            }
        }
        public string Password
        {
            get { return (_password); }
            set
            {
                if (String.IsNullOrEmpty(value))
                    throw new ArgumentException("Password", "Password cannot be empty");

                _password = value;
            }
        }


        public BCPCredentials() { }

        public BCPCredentials(string instance_name, string database_name,
            bool use_integrated_security, string user_name,
            string password_name)
        {
            InstanceName = instance_name;
            DatabaseName = database_name;
            UserName = user_name;
            Password = password_name;
            UseIntegratedSecurity = use_integrated_security;

        }



        public string ConnectionString
        {
            get
            {
                if (String.IsNullOrEmpty(InstanceName))
                    throw new ArgumentException("InstanceName", "Not declared a valid InstanceName");
                if (String.IsNullOrEmpty(DatabaseName))
                    throw new ArgumentException("DatabaseName", "Not declared a valid DatabaseName");
                if (UseIntegratedSecurity == false && (String.IsNullOrEmpty(UserName) || String.IsNullOrEmpty(Password)))
                    throw new ArgumentException("User or Password", "User and Password cannot be empty");

                return (SolidQSqlConnection.SolidQSqlConnection.BuildConnectionString(InstanceName, DatabaseName, UseIntegratedSecurity, UserName, Password, "SolidQ BCP"));
            }
        }
    }
}